<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// let map = new Map([
			// 	[20, 0],
			// 	[10, 0],
			// 	[5, 0]
			// ]);
			// var lemonadeChange = function(bills) {
			// 	for (const bill of bills) {
			// 		map.set(bill, map.get(bill) + 1);
			// 		if (!judge(bill - 5)) return false;
			// 	}
			// 	return true;
			// };

			// function judge(amount) {
			// 	for (let [key, value] of map.entries()) {
			// 		while (amount >= key && value > 0) {
			// 			amount -= key;
			// 			map.set(key, value - 1);
			// 		}
			// 	}
			// 	return amount == 0;
			// }
			var lemonadeChange = function(bills) {
			    let five = 0, ten = 0;
			    for (const bill of bills) {
			        if (bill === 5) {
			            five += 1;
			        } else if (bill === 10) {
			            if (five === 0) {
			                return false;
			            }
			            five -= 1;
			            ten += 1;
			        } else {
			            if (five > 0 && ten > 0) {
			                five -= 1;
			                ten -= 1;
			            } else if (five >= 3) {
			                five -= 3;
			            } else {
			                return false;
			            }
			        }
			    }
			    return true;
			};
			// console.log(lemonadeChange([5, 5, 5, 10, 20]));
			console.log(lemonadeChange([5, 5, 10, 10, 20]));
			// console.log(lemonadeChange([5, 5, 5, 10, 20]));
		</script>
	</body>
</html>
